package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;

import java.util.ArrayList;
import java.util.List;

public class ProduceEditOrderWorkpartAdapter1 extends BaseAdapter {
    private Context context;
    private List<WorkPartBean> datas = new ArrayList<WorkPartBean>();
    private LayoutInflater inflater;

    public ProduceEditOrderWorkpartAdapter1(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setData(List<WorkPartBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public WorkPartBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_produce_edit_order_workpart1, null);
            holder.tv_workpart_name = convertView.findViewById(R.id.tv_workpart_name);
            holder.tv_last_workpart = convertView.findViewById(R.id.tv_last_workpart);
            holder.tv_workpart_status = convertView.findViewById(R.id.tv_workpart_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final WorkPartBean workPartBean = datas.get(position);
        holder.tv_workpart_name.setText(workPartBean.getWorkPartName());
        if (workPartBean.isLastWorkPart()) {
            holder.tv_last_workpart.setVisibility(View.VISIBLE);
        } else {
            holder.tv_last_workpart.setVisibility(View.GONE);
        }

        CommonEnum.ProduceOrderStatus status = workPartBean.getStatus();
        if (null!=status){
            if (status==CommonEnum.ProduceOrderStatus.CREATED){
                holder.tv_workpart_status.setText("");
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.rgb_00000000));

            }else if (status==CommonEnum.ProduceOrderStatus.EDIT){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.edit));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.color_619dd1));

            }else if (status==CommonEnum.ProduceOrderStatus.EDITED){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.edited));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));

            }else if (status==CommonEnum.ProduceOrderStatus.SEND){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.wait_receive));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.rgb_FFC000));

            }else if (status==CommonEnum.ProduceOrderStatus.RECEIVED){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.already_received));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));

            }else if (status==CommonEnum.ProduceOrderStatus.RETURNED){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.order_back));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.rgb_C00000));

            }else if (status==CommonEnum.ProduceOrderStatus.COMPLETED){
                holder.tv_workpart_status.setText(context.getResources().getString(R.string.order_completed));
                holder.tv_workpart_status.setTextColor(context.getResources().getColor(R.color.color_87c688));

            }
        }

        return convertView;
    }

    static class ViewHolder {
        TextView tv_workpart_name;
        TextView tv_last_workpart;
        TextView tv_workpart_status;
    }
}
